<template>
  <div
    class="modal fade"
    tabindex="-1"
    role="dialog"
    aria-hidden="true"
    :id="id"
  >
    <div class="modal-dialog modal-dialog-centered">
      <div class="modal-content">
        <div class="modal-header">
          <h4 class="modal-title">
            <slot name="title"> 新增航空公司信息 </slot>
          </h4>
          <button
            type="button"
            class="btn-close"
            data-bs-dismiss="modal"
            aria-label="Close"
          ></button>
        </div>
        <div class="modal-body">
          <form id="frmUser" role="form" class="form-horizontal">
              <div class="row mb-2">
                <label class="control-label col-4"> 两字代码 </label>
                <div class="col-8">
                  <input
                    type="text"
                    class="form-control"
                    v-model.trim="twoCode"
                  />
                </div>
              </div>
              <div class="row mb-2">
                <label class="control-label col-4"> 三字代码 </label>
                <div class="col-8">
                  <input
                    type="text"
                    class="form-control"
                    v-model.trim="threeCode"
                  />
                </div>
              </div>
              <div class="row mb-2">
                <label class="control-label col-4"> 中文名 </label>
                <div class="col-8">
                  <input type="text" class="form-control" v-model.trim="name" />
                </div>
              </div>
              <div class="row mb-2">
                <label class="control-label col-4"> 中文简称 </label>
                <div class="col-8">
                  <input
                    type="text"
                    class="form-control"
                    v-model.trim="nickName"
                  />
                </div>
              </div>
              <div class="row mb-2">
                <label class="control-label col-4"> 英文名 </label>
                <div class="col-8">
                  <input
                    type="text"
                    class="form-control"
                    v-model.trim="englishName"
                  />
                </div>
              </div>
              <div class="row mb-2">
                <label class="control-label col-4"> 英文简称 </label>
                <div class="col-8">
                  <input
                    type="text"
                    class="form-control"
                    v-model.trim="englishNickName"
                  />
                </div>
              </div>
            </form>
        </div>
        <div class="modal-footer">
          <button
            type="button"
            class="btn btn-secondary me-2"
            data-bs-dismiss="modal"
          >
            关闭
          </button>
          <button type="button" class="btn btn-primary" @click.stop="ok()">
            确定
          </button>
        </div>
      </div>
    </div>
  </div>
</template>


<script>
import $ from "jquery";

export default {
  props: {
    nullable: {
      type: Boolean,
      default: true,
    },
    id: {
      type: String,
      default: "airlinesModal",
    },
    departments: {
      type: Array,
    },
  },
  data() {
    return {
      resolve: "",
      reject: "",
      promise: "",

      airlinesId: 0,
      threeCode: "",
      twoCode: "",
      name: "",
      englishName: "",
      nickName: "",
      englishNickName: "",

      myModal: null,
    };
  },
  methods: {
    ok: function () {
      this.hideModal();

      this.resolve({
        id: this.airlinesId,
        threeCode: this.threeCode,
        twoCode: this.twoCode,
        name: this.name,
        nickName: this.nickName,
        englishName: this.englishName,
        englishNickName: this.englishNickName,
      });
    },
    modal: function (v) {
      this.airlinesId = v.id;
      this.threeCode = v.threeCode;
      this.twoCode = v.twoCode;
      this.name = v.name;
      this.nickName = v.nickName;
      this.englishName = v.englishName;
      this.englishNickName = v.englishNickName;

      this.showModal();

      this.promise = new Promise((resolve, reject) => {
        this.resolve = resolve;
        this.reject = reject;
      });
      return this.promise;
    },
    showModal: function () {
      this.getMyModal().show();
    },
    hideModal: function () {
      this.getMyModal().hide();
    },
    getMyModal: function () {
      if (this.myModal === null) {
        let myModalEl = $(this.$el).get(0);
        this.myModal = new bootstrap.Modal(myModalEl, {
          keyboard: true,
        });
      }

      return this.myModal;
    },
  },
};
</script>
